# -*- coding: utf-8 -*-
#! /usr/bin/env python

from PySide import QtCore, QtGui


class ListWidget(QtGui.QListWidget):
    def __init__(self, parent):
        super(ListWidget, self).__init__(parent)

    def set_items(self, items):
        if self.count():
            for i in range(self.count()):
                self.takeItem(i)

        for i in items:
            item = QtGui.QListWidgetItem(i.title)
            item.id = i.item_id
            item.thread_id = i.parent_id
            self.addItem(item)
        if items: self.setCurrentItem(item)
        
    def keyPressEvent(self, event):
        super(ListWidget, self).keyPressEvent(event)
        if event.key() == QtCore.Qt.Key_Delete:
            self._del_item()

    def _del_item(self):
        for item in self.selectedItems():
            self.takeItem(self.row(item))        